<template>
  <div class="my-selectStore__components">
    <img src="@/assets/images/img_icon/store_icon.svg" />
    <el-cascader
      change-on-select
      popper-class="my__selectStore__components__cascader"
      v-model="value"
      :options="options"
      placeholder="请选择大区"
      :props="{
        label: 'orgName',
        value: 'orgSeq',
        children: 'children',
        checkStrictly: true,
      }"
      @change="optionChange"
    ></el-cascader>
  </div>
</template>
<script>
import { queryStoreOrgseq } from '@/api/memberinfo';
export default {
  name: 'selectStore',
  data() {
    return {
      options: [],
      value: [],
      orgSeq: '',
    };
  },
  methods: {
    optionChange(val) {
      console.log(val);
      this.$emit('handleChange', val);
    },
    getOptions() {
      queryStoreOrgseq({ orgSeq: this.orgSeq }).then((res) => {
        let { records } = res;
        this.options = this.formatOptions(records);
      });
    },
    formatOptions(data) {
      let arr = [];
      for (let i = 0; i < data.length; i++) {
        if (!!data[i].children && data[i].children.length) {
          this.formatOptions(data[i].children);
        } else {
          data[i].children = undefined;
        }
        arr.push(data[i]);
      }
      return arr;
    },
  },
  mounted() {
    this.getOptions();
  },
  created() {
    this.orgSeq =
      JSON.parse(localStorage.getItem('logininfo')).orgList[0].orgSeq || '';
    this.value = [this.orgSeq];
  },
};
</script>
<style lang="scss" scoped>
.my-selectStore__components {
  height: 32px;
  width: 250px;
  display: flex;
  align-items: center;
  img {
    width: 30px;
    height: 32px;
    margin-right: 10px;
  }
  .el-cascader {
    width: 200px;
  }
  .el-cascader-node {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 30px 0 20px;
    height: 34px;
    line-height: 34px;
    outline: none;
  }
}
</style>
<style lang="scss">
.my__selectStore__components__cascader {
  .el-cascader-panel {
    display: flex;
    border-radius: 4px;
    font-size: 14px;
  }
  .el-cascader-node.is-selectable.in-active-path {
    color: #606266;
  }

  .el-cascader-node:not(.is-disabled) {
    cursor: pointer;
  }
  .el-cascader-node {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 30px 0 20px;
    height: 34px;
    line-height: 34px;
    outline: none;
  }
  .el-cascader-node__label {
    flex: 1;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .el-cascader-node.is-selectable.in-active-path {
    color: #606266;
  }
  .el-cascader-node > .el-radio {
    margin-right: 0;
  }
  .el-cascader-node.in-active-path,
  .el-cascader-node.is-active,
  .el-cascader-node.is-selectable.in-checked-path {
    color: #409eff;
    font-weight: 700;
  }
  .el-cascader-node:not(.is-disabled):focus,
  .el-cascader-node:not(.is-disabled):hover {
    background: #f5f7fa;
  }
}
</style>
